package com.zzyl.controller;


import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/nursing_project")
public class NursingProjectController extends BaseController {
    @Autowired
    private NursingProjectService nursingProjectService;

    @GetMapping
    public ResponseResult getByPage(
            @RequestParam(value = "name", required = false) String name ,
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum ,
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize ,
            @RequestParam(value = "status", required = false)  Integer status
    ){
        PageResponse<NursingProjectVo> page = nursingProjectService.getPage(name,pageNum,pageSize,status);
        return success(page);
    }

    @PostMapping
    public ResponseResult add(@RequestBody  NursingProjectDto nursingProjectDto){
        nursingProjectService.add(nursingProjectDto);
        return success();
    }

    @GetMapping("/{id}")
    public ResponseResult getById(@PathVariable Long id){
        NursingProjectVo nursingProjectVo = nursingProjectService.getByid(id);
        return success(nursingProjectVo) ;
    }
    @DeleteMapping("/{id}")
    public ResponseResult delete(@PathVariable("id") Long id){
        nursingProjectService.delete(id);
        return success();
    }
    @PutMapping("/{id}/status/{status}")
    public ResponseResult changeStatus(@PathVariable("id") Long id, @PathVariable("status") Integer status){
        nursingProjectService.changeStatus(id,status);
        return success();
    }
}
